Skip to content

Reimplement 4 MenuItems functions from #530 with register allocation differences - #558

Open
gynt wants to merge 7 commits into
sourcehold:mainfrom
gynt:reimpl/pr530-matched
Open

gynt wants to merge 7 commits into
sourcehold:mainfrom
gynt:reimpl/pr530-matched

Conversation

@gynt

@gynt gynt commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

This PR carries the finished part of draft #530 (reimpl/ui-menuitems-development). That is four functions where only register allocation is left: their assembly has no functional difference from the original. None of the draft's functions is at 100%, so they are marked Register allocation differs, not 100%.

Measured on origin/main (592a17d): I ran a full DLL build with exactly these four files in cmake/openshc-sources.txt.local. Both resolver sets were switched on: the struct resolvers through enable_reimplemented_data.py and the function resolvers through enable_local_functions.py. I then ran reccmp. To check each diff, I normalized register names and stack slots and confirmed that every remaining line is an allocation difference.

Function Address reccmp raw / normalized Status remark What still differs
MenuItemRenderFunction_General_EventButtonAndData 0x004BFFA0 87.6 / 85.3 87.6% | Register allocation differs The colour argument is a register in ours and a per-arm immediate push in the original. The original hoists the three constant pushes above the branch; ours pushes all four after the arms join. Values, argument order and the call are the same.
MenuItemRenderFunction_Roundtable_Main 0x004AEF70 97.2 / 85.5 97.2% | Register allocation differs The two waiting-room text-index loads come in the other order, and the lea for 9*ai + variation + 231 uses other base/index registers. The code is one byte shorter, which shifts branch offsets. reccmp's trailing +ret is an artefact of it cutting the original at our length.
MenuItemActionHandler_SoundOptions_Buttons 0x004940B0 86.6 / 80.9 86.6% | Register allocation differs The original keeps the zero of the sound toggle in eax (xor eax, eax) where ours uses immediates. The two VolumeSlider out-locals swap stack slots. The jump-table entries shift by the size difference.
MenuItemRenderFunction_TextEditor_Scrollbar 0x0045EF90 82.4 / 82.1 82.4% | Register allocation differs y and x + 20 sit in swapped callee-saved registers (edi/ebp). Ours computes top = y - 22 into ebx before the first call; the original computes it after the second call. The value and all its uses are the same.

Style pass: done per REIMPLEMENTATION_STYLE_GUIDE.md on main, folded into each function's commit. Every change was re-measured with the full build above, and all four percentages stayed the same.

  • Names instead of param_1/local_N: itemIndex, clickType, minValue/maxValue.
  • Named constant text position in EventButtonAndData.
  • COL_C2F0EB/COL_CCFAFF instead of raw colours.
  • Decimal literals.
  • BOOLEnum for the genie toggle.
  • +=.
  • No redundant casts and no unused usings.
  • Comments on the closing namespaces.
  • SoundOptions passes its own currentValue local for the default volume.

Header changes: none.

GL / visibility entries: none needed.

Overlap with open PRs: none outside draft #530.

Left in the draft, because differences other than allocation remain:

  • handleMenuElementsCallbacks (70.7): memory operands are folded into the instructions in one version and loaded separately in the other (add r, [m], cmp [m], imm), and the instruction order differs.
  • MenuItemRenderFunction_BuildingAndStatusMenu_BuildingWorkStatus (89.0): block layout and tail duplication.
  • MenuItemActionHandler_General_CreateEventCallbackFunction (90.0): tail layout around playEventVideoBik.
  • MenuItemActionHandler_UnusedCreateMessageEvent_SetTextUnk (84.0): the original duplicates the case-0x13 tail.

Draft #530 stays open for those functions.

Pre-review pass (f8f25ca): SoundOptions drops the reuse of the parameter slot through an enum cast, and the code comment that explained it. The forms that are kept because the match needs them are listed in the PR thread. The four measurements are unchanged.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp

gynt and others added 4 commits December 4, 2026 16:09
…eral_EventButtonAndData, register allocation differs

Taken from draft sourcehold#530 with the style pass applied. Measured on main
592a17d with the four files of this PR in .local, both resolver sets
enabled, full build and reccmp. Style: itemIndex instead of param_1, named const text position, COL_C2F0EB/COL_CCFAFF, decimal literals, no redundant cast or unused usings.
The only remaining difference is how the colour argument reaches the call: the original pushes the colour immediate in each arm, with the three constant pushes before it hoisted above the branch, while ours keeps the colour in edx and pushes all four after the arms join. The values, the argument order and the call are the same.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
…ndtable_Main, register allocation differs

Taken from draft sourcehold#530 with the style pass applied. Measured on main
592a17d with the four files of this PR in .local, both resolver sets
enabled, full build and reccmp. Style: itemIndex instead of param_1, decimal literals, no unused usings.
The only remaining differences are allocation ones: the two waiting-room text index loads (currentAIArray and aiVariationArray) are loaded in the other order into other registers, and the base/index registers of the 9*ai + variation + 231 lea differ. The code is one byte shorter, which moves branch offsets; reccmp's trailing +ret is an artefact of it cutting the original at our length.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
…dOptions_Buttons, register allocation differs

Taken from draft sourcehold#530 with the style pass applied. Measured on main
592a17d with the four files of this PR in .local, both resolver sets
enabled, full build and reccmp. Style: clickType instead of param_1, minValue/maxValue instead of local_4/local_8, BOOLEnum for the genie toggle, comment on the parameter slot reuse.
The only remaining differences are allocation ones: the original holds the zero for the sound toggle in eax (xor eax, eax) where ours uses immediates, and the two VolumeSlider out-locals swap stack slots. The jump table entries move by the resulting size difference.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
…tEditor_Scrollbar, register allocation differs

Taken from draft sourcehold#530 with the style pass applied. Measured on main
592a17d with the four files of this PR in .local, both resolver sets
enabled, full build and reccmp. Style: += for the bottom edge.
The only remaining differences are allocation ones: y and x+20 live in other callee-saved registers (edi/ebp swapped), and ours computes top = y - 22 into ebx before the first call where the original computes it after the second; the value and every use are the same.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
@gynt gynt changed the title Reimplement 0 MenuItems functions at 100% from #530, plus 4 with register allocation differences Reimplement 4 MenuItems functions from #530 with register allocation differences Dec 4, 2026
- SoundOptions_Buttons: the reset-volume cases pass their own
  currentValue local instead of reusing the click-type parameter's slot
  through an enum cast, the comment explaining that form is gone, and the
  genie toggle tests the flag by truthiness.

Re-measured on main 592a17d with a full build and reccmp, unchanged:
87.6 / 97.2 / 86.6 / 82.4, all still register allocation only.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
@gynt

gynt commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

These forms stay as they are because they are needed for the match. Each was measured with a full build and reccmp on main 592a17d.

MenuItemRenderFunction_General_EventButtonAndData

  • month is read in both arms of the colour if instead of once before it. Reading it once before the if drops the function from 87.6% to 52.5%.
  • The colour stays a variable that both arms set and one call uses. That variable is the only remaining difference: the original pushes the colour as an immediate in each arm, so the function is Register allocation differs.

MenuItemRenderFunction_Roundtable_Main

  • The blend strength for button 20 is written (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32. The original computes that expression and does not fold it. Writing just DAT_ButtonBackgroundBlendStrength::instance drops the function from 97.2% to 84.9%.
  • DAT_ButtonCurrentlyInteracting::instance is tested twice around the renderGMWithAlphaMask call, because the original reloads it after the call.

MenuItemActionHandler_SoundOptions_Buttons

  • No match-driven form remains. The reset-volume cases now pass their own currentValue local instead of reusing the click-type parameter's slot through (SoundMenuClickType)90, and the measurement is unchanged.

MenuItemRenderFunction_TextEditor_Scrollbar

  • No match-driven form remains. param_1/param_3 are unused. Their names come from TextEditor.hpp, which this PR does not change.

gynt and others added 2 commits December 4, 2026 23:38
Each removed cast leaves the generated code and the warnings unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant